<template>
  <el-dialog :title="title" :close-on-click-modal="false" :fullscreen="true" :visible.sync="visible"
    :before-close="cancel" class="JNPF-dialog JNPF-dialog_center" lock-scroll width="50%">
    <el-row class="JNPF-common-search-box" :gutter="16">
      <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">
        
        <el-col :span="8">
            <el-form-item class="required" label="设备编号" prop="FCATNO">
              <el-input
                v-model="dataForm.FCATNO"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="设备类型">
              <el-select v-model="dataForm.FCATTYPE" placeholder="请选择">
                <el-option
                  v-for="item in options2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="控制面板">
              <el-select v-model="dataForm.FCONTORL" placeholder="请选择">
                <el-option
                  v-for="item in options3"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="设备名称" prop="FCATNAME">
              <el-input
                v-model="dataForm.FCATNAME"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="设备品牌" prop="FBRAND">
              <el-input
                v-model="dataForm.FBRAND"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="设备型号" class="required" prop="FSPEC">
              <el-input
                v-model="dataForm.FSPEC"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="库存单位" prop="FUNIT">
              <el-input
                v-model="dataForm.FUNIT"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="使用年限" prop="FUSEYEAR">
              <el-input
                v-model="dataForm.FUSEYEAR"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="设备条码" prop="FBARCODE">
              <el-input
                v-model="dataForm.FBARCODE"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="工作电流" prop="FDY">
              <el-input
                v-model="dataForm.FDY"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="最低电压" prop="FLOWDY">
              <el-input
                v-model="dataForm.FLOWDY"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="最高电压" prop="FHEIGHTDY">
              <el-input
                v-model="dataForm.FHEIGHTDY"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item class="required" label="采购周期" prop="FORDWEEK">
              <el-input
                v-model="dataForm.FORDWEEK"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="设备图片" prop="ficon2" width="120px">
              <el-upload
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload">
                <img style="width: 280px; height: 80px"
                     v-if="imageUrl1" :src="imageUrl1" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
        </el-col>

        <el-col :span="5">
          <el-form-item label="">
            <!-- <el-button type="success" icon="el-icon-plus" @click="insert">添加场地</el-button> -->
            <el-button type="primary" :loading="loading">返回</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>

   <template>
     <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="控制指令" name="first">
        <el-table :data="list" border stripe>
          <el-table-column label="操作" width="80">
            <template slot-scope="scope">
              <el-button slot="reference" icon="el-icon-delete" style="color: red" @click="shopdate(scope.$index)"
                type="text">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="FENTRYID" label="序号" width="75" ></el-table-column>
          <el-table-column prop="FCONTROL" label="控制指令" width="105"></el-table-column>
          <el-table-column prop="FCATNOTE" label="指令描述" width="105"></el-table-column>
          <el-table-column prop="FCATCON" label="设备指令" ></el-table-column>
          <el-table-column prop="FCATITEM" label="设备标识" width="85"></el-table-column>
          <el-table-column prop="FNUMFLAG" label="数字属性" width="85"></el-table-column>
          <el-table-column prop="FLOW" label="最低值" width="85"></el-table-column>
          <el-table-column prop="FHEIGHT" label="最高值" width="85"></el-table-column>
       </el-table>
        <div class="addbox">
             <el-link icon="el-icon-plus" type="primary" >添加一行</el-link>
        </div>
      </el-tab-pane>
      <el-tab-pane label="输出参数" name="second">
        <el-table :data="list2" border stripe>
          <el-table-column label="操作" width="80">
            <template slot-scope="scope">
              <el-button slot="reference" icon="el-icon-delete" style="color: red" @click="shopdate(scope.$index)"
                type="text">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="FENTRYID" label="序号" ></el-table-column>
          <el-table-column prop="FWORKNO" label="参数编号" ></el-table-column>
          <el-table-column prop="FWORKNAME" label="参数描述"></el-table-column>
          <el-table-column prop="FWORKTYPE" label="参数类型"></el-table-column>
          <el-table-column prop="FMEMO" label="备注信息" ></el-table-column>
       </el-table>
        <div class="addbox">
             <el-link icon="el-icon-plus" type="primary" >添加一行</el-link>
        </div>
      </el-tab-pane>
      <el-tab-pane label="预约设置" name="third">
        <el-row class="JNPF-common-search-box" :gutter="16">
         <el-form @submit.native.prevent ref="elForm" :model="dataForm" :rules="rules">
          <el-col :span="8">
            <el-form-item label="收费方式">
              <el-select v-model="dataForm.FCHARGETYPE" placeholder="请选择">
                <el-option
                  v-for="item in options4"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
              <el-form-item class="required" label="收费标准" prop="FCHARGEAMT">
                <el-input
                  v-model="dataForm.FCHARGEAMT"
                  placeholder="请输入"
                  clearable
                  :style="{ width: '100%' }"
                >
                </el-input>
              </el-form-item>
          </el-col>

          <el-col :span="8">
              <el-form-item class="required" label="是否预约" prop="FISUSE">
                <template>
                  <!-- `checked` 为 true 或 false -->
                  <el-checkbox v-model="checked"></el-checkbox>
                </template>
              </el-form-item>
          </el-col>

        </el-form>
       </el-row>
      </el-tab-pane>
      <!-- <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane> -->
    </el-tabs>
  </template>
    
    <StudqueryFcuston ref="StudqueryFcuston" @confirm="shoplist" />
  </el-dialog>
</template>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>

<script>
  import StudqueryFcuston from "@/components/StudqueryFcuston/StudqueryFcuston.vue"
  import jnpf from "@/utils/jnpf"
  export default {
    components: { StudqueryFcuston },
    props: {
      formationlist: {
        type: Array,
        default: [],
      },
    },
    data() {
      return {
        imageUrl1:require('@/assets/images/me/equipment.png'),
        activeName: 'first',
        title: "新增",
        insertorupdate: true,
        dataForm: {
          FCATNO :"1003",
          FITEMTYPE:"空调",
          FCATTYPE:"空调",
          FCATNAME:"春兰空调",
          FCONTORL: "红外",
          FSPEC: "2021-1-A",
          FBRAND: "春兰",
          FUNIT: "台",
          FUSEYEAR: "10",
          FDY: "10",
          FLOWDY: "215",
          FHEIGHTDY:"225",
          FBARCODE:"210038",
          FORDWEEK:"30",
          FIMAGE:"",
          FCHARGETYPE:"小时",
          FCHARGEAMT:0,
          FNOTE: ""
        },
        rules: {
          FCATNO:[
            { required: true, message: '请输入设备编号', trigger: 'blur' },
          ],
          FCATNAME: [
            { required: true, message: '请输入设备名称', trigger: 'blur' },
          ],
          FBRAND: [
            { required: true, message: '请输入设备型号', trigger: 'blur' },
          ],
        },
        list: [{  "FENTRYID":1,
                  "FCONTROL": "OFF",
                  "FCATNOTE": "制冷",
                  "FCATCON": "30010015180102010101020D002301CB0226030105200780FF39",
                  "FCATITEM": "switch_1",
                  "FNUMFLAG": "0",
                  "FLOW": "",
                  "FHEIGHT": ""
                },
                { "FENTRYID":2,
                  "FCONTROL": "POWER",
                  "FCATNOTE": "电源",
                  "FCATCON": "30010015180102010101010D002301CB0226030105200780FF38",
                  "FCATITEM": "switch_1",
                  "FNUMFLAG": "0",
                  "FLOW": "",
                  "FHEIGHT": ""
                }],
        list2: [{  "FENTRYID":1,
                  "FWORKNO": "101",
                  "FWORKNAME": "温度",
                  "FWORKTYPE":"float",
                  "FMEMO": ""
                },
                { "FENTRYID":2,
                  "FWORKNO": "102",
                  "FWORKNAME": "湿度",
                  "FWORKTYPE":"float",
                  "FMEMO": ""
                }],
        loading: false,
        visible: false,

        //所属校区选择数据
        options1: [{
          value: '10',
          label: '单插'
        }, {
          value: '20',
          label: '双开'
        }, {
          value: '21',
          label: '空调'
        }, {
          value: '22',
          label: '通风柜'
        }, {
          value: '23',
          label: '智能柜'
        },
      ],

        //所属楼层选择数据
        options2: [{
          value: '20E01',
          label: '电器'
        }, {
          value: '20E02',
          label: '空调'
        }, {
          value: '20N01',
          label: '智能柜'
        }, {
          value: '20N02',
          label: '通风柜'
        }],
        
        //所属楼层选择数据
        options3: [{
          value: '20E01',
          label: '普通'
        }, {
          value: '20E02',
          label: '空开'
        }, {
          value: '20N01',
          label: '单火开关'
        }, {
          value: '20N02',
          label: '红外'
        }],

        //所属楼层选择数据
        options4: [{
          value: '1',
          label: '小时'
        }, {
          value: '2',
          label: '每次'
        }],

      };
    },
    created() {
    },
    mounted() { },
    methods: {
      handleClick(tab, event) {
        console.log(tab, event);
      },
      //
      init(FBILLNO) {
        this.dataForm.FBILLNO = FBILLNO;
        if (this.dataForm.FBILLNO) {
          this.title = "修改"
          this.insertorupdate = false;
        }
        else {
          this.title = "新增"
          this.dataForm.FBILLNO = "K" + Math.floor(Math.random() * 10000000) + 1;
          this.insertorupdate = true;
        }
        this.visible = true;
      },
      insert() {
        this.$refs.StudqueryFcuston.open();
      },
      shoplist(data) {
        data.forEach(item => {
          this.list.push({
            FBILLNO: this.dataForm.FBILLNO
            , FENTRYID: "1"
            , FYEAR: 2024
            , FGRADE: "大一"
            , FCLASS: "化学系1班"
            , FSTUDNAME: "曹操"
          },{
            FBILLNO: this.dataForm.FBILLNO
            , FENTRYID: "2"
            , FYEAR: 2024
            , FGRADE: "大一"
            , FCLASS: "化学系1班"
            , FSTUDNAME: "刘备"
          })
        });
      },
      //
      cancel() {
        this.$refs.elForm.resetFields();
        this.list = [];
        this.visible = false;
      },

      handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isLt2M = file.size / 1024 / 1024 < 2;

        if (!isJPG) {
          this.$message.error('上传头像图片只能是 JPG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传头像图片大小不能超过 2MB!');
        }
        return isJPG && isLt2M;
      },

    },
  };
</script>